<?php
session_start();
error_reporting(E_ALL && ~ E_NOTICE);
include '../../db/dbConnect.php';
include '../function/helper.php';
include '../function/pagging.php';
?>
<style type="text/css">
a.pag_nav{
	font-size:12px;
	font-weight:100;
}
.q{
	color:#009F00;
	font-size:16px;
	font-weight:bold;
    margin: 5px 0px;

}
.q, .td{
    background: lavenderblush;
}
.ans{
	font-size:16px;
}
#new_question tr{
    line-height: 40px;
    height:40px;
}
#new_question{
    background: whitesmoke;
}
</style>
<script type="text/javascript">
	$('a.skip').hide();
	
	$("a.ans").bind('click',function(){
        var $this=$(this),
        	id=$this.attr("id");

		//alert(id);
		$.ajax({
			type:'get',
			url:'web/member/list_ans.php',
			data:'idquest='+id+'&kind=new_ans',
			success:function(result){
				//alert(result);
				$this.parents('tr').find('div.wrap_ans').removeClass('hidden').empty()
					.hide().append(result).css({ "margin":"0"}).fadeIn();
				//$(".ul_level").css({"marginTop":"40px"});
				//$this.parents("div.wrap_ans").hide();
				$('input.skip').hide();
			}
		});

		$this.hide();
        $this.siblings('a.skip').fadeIn('slow');
		return false;
	});

	$("a.skip").bind('click',function(){
		$(this).parents('tr').find('div.wrap_ans').css({"margin":"10px 0px"}).slideUp('slow');
		$(this).parents('tr').css({"height":"40px"});
		$(this).siblings('a.ans').show();
		$(this).hide();
		return false;
	});

	$('a.pag_nav').click(function(){
		var $href=$(this).attr('href');
		//alert($href);
		$("div.pLeft").load($href);
		return false;
	});
		var $iduser=$(".question").attr('user');
</script>
<?php
if($_SERVER['REQUEST_METHOD']=="GET" and ($_GET["user_profile"])){
    $user=$_GET["user_profile"];
}else {
    //unset($user);
    $user=$_SESSION['LoginData']['iduser'];
}
?>
<div id="new_question" class="question" user="<?php echo $user;?>">
    <h3 class="hh">Những câu hỏi bạn chưa trả lời</h3>
    <table width="98%" border="0" cellspacing="" cellpadding="">

  <?php 

	
	$p=new Pager();	
	$p->setLimit(10);
	$p->findStart($p->getLimit());
	$sql='select * from u_profile_question as q
		where  q.idpr_question NOT IN(
								select uqa.idquestion
								from u_quest_answer as uqa
								where uqa.iduser="'.$user.'")
			and kind=0 order by q.idpr_question asc';

	$result=mysql_query($sql);
	echo mysql_error();
	$count=0;
	$count=mysql_num_rows($result);
	$p->findPages($count, $p->getLimit());
	$start=$p->getStart();
	$limit=$p->getLimit();
		$sql='select * from u_profile_question as q
		where  q.idpr_question NOT IN(
								select uqa.idquestion
								from u_quest_answer as uqa
								where uqa.iduser="'.$user.'")
			and kind=0 order by q.idpr_question asc 
			limit '.$start.','.$limit;
			$result=mysql_query($sql);
			echo mysql_error();
			while($row=mysql_fetch_array($result)){
			//print_r($row);
			
	?>
    <tr>
    <td>
        <div class="answer"><div class="q"><?php echo $row['question'];?></div>
        <div class="wrap_ans hidden" >
        </div><!--end wrap_ans-->
        </div></td>
    <td class="td w15p"><a href="#" id="<?php echo $row['idpr_question']?>" class="btn-icon ans ">Trả lời</a>
    <a href="#" id="<?php echo $row['idpr_question']?>" class="btn-icon skip">Để lúc khác</a></td>
  	</tr>


    
    
    <?php }?>
    <tr><td><?php $page=$p->pageList($_GET["page"],$p->getPage());
		echo $page;
	?></td>
    <td><?php echo($p->getStart()+1).' - '.((($end=($p->getStart()+$p->getLimit()))>$count)?$count:$end).'/'.$count.'';?></td>
    </tr>
</table>
    
</div>
